package com.drug.mingkang.controller;

import com.drug.mingkang.model.HqMarket;
import com.drug.mingkang.model.vo.HqMarketVo;
import com.drug.mingkang.permission.model.PerRole;
import com.drug.mingkang.permission.model.PerUsers;
import com.drug.mingkang.service.HqMarketService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

/**
 * 总公司销售(HqMarket)表控制层
 *
 * @author wenchangjian
 * @since 2020-08-11 12:00:13
 */
@RestController
@RequestMapping("hqMarket")
public class HqMarketController {
    /**
     * 服务对象
     */
    @Resource
    private HqMarketService hqMarketService;

    /**
     * 通过主键查询单条数据  附 销售明细
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation(value = "通过主键查询单条数据  附 销售明细", notes = "销售Id", httpMethod = "GET", response = PerRole.class)
    @GetMapping("/findById/{id}")
    @ResponseBody
    public HqMarket findById(@PathVariable("id") String id) {
        return hqMarketService.queryById(id);
    }

    @ApiOperation(value = "查询当前登录 公司财务 今日销量 以及本月销量", notes = "", httpMethod = "POST", response = List.class)
    @PostMapping("/findTodaysSalesOrMonthSales")
    public List<Integer> findTodaysSalesOrMonthSales(HttpSession session) {
        PerUsers perUsers = (PerUsers) session.getAttribute("perUsers");
        //判断是否总公司
        String z = "0";
        if (z.equals(perUsers.getCompanyId())) {
            return hqMarketService.findTodaysSalesOrMonthSales(z);
        } else {
            return hqMarketService.findTodaysSalesOrMonthSales(perUsers.getCompanyId());
        }
    }

    /**
     * 显示总公司所有销售订单
     *
     * @param hqMarketVo 实例对象
     * @return
     */
    @ApiOperation(value = "显示总公司所有销售订单", notes = "显示总公司所有销售订单", httpMethod = "POST", response = Map.class)
    @ResponseBody
    @PostMapping("/showList")
    public Map<String, Object> showList(HqMarketVo hqMarketVo) {
        Map<String, Object> map = hqMarketService.queryAllByLimit(hqMarketVo);
        return map;
    }

    /**
     * 显示总公司所有申请退款的订单
     * @author Mr.wang
     */

}